#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
主题: 排列组合的迭代
问题: 你想迭代遍历一个集合中元素的所有可能的排列或组合
提示 : 
"""

def recipe1():
    items = ['a', 'b', 'c']
    from itertools import permutations
    for p in permutations(items):
        print(f"{p = }")

    # 指定长度的所有排列
    for p1 in permutations(items, 2):
        print(f"{p1 = }")

    # 输入集合中元素的所有的组合
    from itertools import combinations
    for c in combinations(items, 3):
        print(f"{c = }")

    for c1 in combinations(items, 2):
        print(f"{c1 = }")

    for c2 in combinations(items, 1):
        print(f"{c2= }")

    # 同一个元素被选择多次
    from itertools import combinations_with_replacement
    for c3 in combinations_with_replacement(items, 3):
        print(f"{c3= }")
        
def main():
    print('recipe1'.center(20, '*'))
    recipe1() 

if __name__ == '__main__':
    main()                 